# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=cssselect
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.9.1
pkgrel=4
pkgdesc="Caching and sessions WSGI middleware for use with web applications and stand-alone Python scripts and applications (mingw-w64)"
arch=('any')
license=('BSD')
url="https://pypi.python.org/pypi/cssselect"
makedepends=("${MINGW_PACKAGE_PREFIX}-python2" "${MINGW_PACKAGE_PREFIX}-python3")
source=("https://pypi.python.org/packages/source/c/cssselect/${_realname}-${pkgver}.tar.gz")
sha256sums=('0535a7e27014874b27ae3a4d33e8749e345bdfa62766195208b7996bf1100682')

prepare() {
  cd "${srcdir}"
  sed -e "s|# coding: utf8|# -*- encoding:utf-8 -*-|g" -i ${_realname}-${pkgver}/setup.py
  cp -r ${_realname}-${pkgver} build-python2
  cp -r  ${_realname}-${pkgver} build-python3
}

build() {
  cd "${srcdir}/build-python2"
  # Fix python2 shebang
  sed -i 's|#!/usr/bin/env python|#!/usr/bin/env python2|' cssselect/tests.py
  ${MINGW_PREFIX}/bin/python2 setup.py build

  cd "${srcdir}/build-python3"
  ${MINGW_PREFIX}/bin/python3 setup.py build
}

package_python2-cssselect() {
  pkgdesc="A Python2 library that parses CSS3 Selectors and translates them to XPath 1.0"
  depends=("${MINGW_PACKAGE_PREFIX}-python2>")

  cd "${srcdir}/build-python2"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=;--install-purelib=;--install-data=" \
    ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE"
}

package_python3-cssselect() {
  pkgdesc="A Python3 library that parses CSS3 Selectors and translates them to XPath 1.0"
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd "${srcdir}/build-python3"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=;--install-purelib=;--install-data=" \
    ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE"
}

package_mingw-w64-i686-python2-cssselect() {
  package_python2-cssselect
}

package_mingw-w64-i686-python3-cssselect() {
  package_python3-cssselect
}

package_mingw-w64-x86_64-python2-cssselect() {
  package_python2-cssselect
}

package_mingw-w64-x86_64-python3-cssselect() {
  package_python3-cssselect
}
